package com.lxf.cn.web;

import com.alibaba.fastjson.JSONObject;
import com.lxf.cn.rabbitmq.Prodecer;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by liaoxuefeng on 2018/11/12.
 */

@Controller
@RequestMapping("/rabbitmq")
public class RabbitMqController {


    @Autowired Prodecer prodecer;
    /**
     * mq
     */
    @GetMapping("/send")
    public @ResponseBody String rabbitmq() {
        try{
            prodecer.send("看能保存到明天吗", MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
            JSONObject json = new JSONObject();
            json.put("name", "看能保存到明天吗");
            prodecer.send(json.toString(), MessageProperties.CONTENT_TYPE_JSON);
            return "发送成功" ;
        }catch (Exception e){
            e.printStackTrace();
            return "发送失败" ;
        }


    }






}
